widgetpaintable: Implement get_current_image()
authorBenjamin Otte <otte@redhat.com>
Mon, 2 Apr 2018 06:04:39 +0000 (08:04 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 5 Apr 2018 12:56:39 +0000 (14:56 +0200)
Now that snapshot and empty paintables exist, this is rather trivial.

gtk/gtkwidgetpaintable.c

index 948beb1b23bd5109db7859287679a59182d8e1b0..4ed58a04652ce76be0ad497874a4bfd1a98d594c 100644 (file)
@@ -125,13 +125,22 @@ static GdkPaintable *
 gtk_widget_paintable_paintable_get_current_image (GdkPaintable *paintable)
 {
   GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
+  GtkSnapshot *snapshot;
+  int width, height;
 
   self->contents_invalid = FALSE;
   self->size_invalid = FALSE;
 
-  g_warning ("FIXME: Implement once we can create paintables from render nodes");
+  width = gdk_paintable_get_intrinsic_width (paintable);
+  height = gdk_paintable_get_intrinsic_width (paintable);
+  if (width == 0 || height == 0)
+    return gdk_paintable_new_empty (width, height);
 
-  return NULL;
+  snapshot = gtk_snapshot_new (FALSE, "WidgetPaintableCurrentImage");
+  gdk_paintable_snapshot (GDK_PAINTABLE (self), 
+                          snapshot,
+                          width, height);
+  return gtk_snapshot_free_to_paintable (snapshot, &(graphene_size_t) { width, height });
 }
 
 static int